﻿@{
    List<App.Domain.Company> _Comapnies = ViewData[AppConstants.ViewDataKeys.COMPANY_LIST] as List<App.Domain.Company>;
    int _CellCounter = 0;
    int _NumberOfColumns = 3;
}
<div>
    <table class="company-logo-list" cellpadding="3" cellspacing="0">
        <colgroup>
            <col style="width:25%;" />
            <col style="width:25%;" />
            <col style="width:25%;" />
            <col />
        </colgroup>
    @for (int i = 0; i < _Comapnies.Count; i++)
    {
        App.Domain.Company company = _Comapnies[i];
        String companyUrl = Url.Content(String.Format("~/{0}", company.CompnayUrl));        
        _CellCounter++;
        String tdClass = _CellCounter == _NumberOfColumns ? " class=last" : String.Empty;
        if ((_CellCounter % _NumberOfColumns) == 1){ //If this is the first cell of the row
        @:<tr>
        }
            <td@tdClass>
                <table cellpadding="0" cellspacing="0">
                    <tr>
                        <td style="width:92px;"><a href="@companyUrl">@Html.LogoThumb(company.LogoFile, company.ID, company.Name, Url)</a></td>
                        <td style="padding-left:5px;">
                            <a href="@companyUrl">@company.Name</a>
                            <div>@company.Slogan</div>
                            <div>
                                @((company.Address == AppConstants.UI.BLANK_FIELD_DATA) ? "" : company.Address),@((company.District.Name == AppConstants.UI.BLANK_FIELD_DATA) ? "" : company.District.Name)
                            </div>
                        </td>
                    </tr>
                </table>
                @*<div class="float-left" style="width:92px;">
                    <a href="@companyUrl">@Html.LogoThumb(company.LogoFile, company.ID, company.Name, Url)</a>
                </div>
                <div class="float-left" style="margin-left:10px;">
                    <a href="@companyUrl">@company.Name</a>
                    <div>@company.Slogan</div>
                    <div>
                        @company.Address
                    </div>
                </div>
                <div class="clear"></div>*@
            </td>
        if((_CellCounter % _NumberOfColumns) == 0 || i == (_Comapnies.Count - 1)){
            _CellCounter = 0;
            if (i == (_Comapnies.Count - 1))
            {
                int remainingCells = _NumberOfColumns - (_Comapnies.Count % _NumberOfColumns);
                if (remainingCells > 0 && remainingCells < _NumberOfColumns)
                {
                    <td colspan="@remainingCells"></td>
                }                    
            }
        @:</tr>
        }        
    }    
    </table> 
</div>
@*@Html.BuildCompanyAddress(company.Address, company.District.Name, company.District.Country.Name, company.Phone, company.Fax, company.Email, company.Web);*@